<?php
/**
 * Description of LanceService
 *
 * @author Magno
 */
class LanceService {


    private $lanceDAO;
    function __construct() {
        $this->lanceDAO = new LanceDAO();
    }


    public function salvar($lance) {

        try {
            return $this->lanceDAO->salvar($lance);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function salvarSimples($lanceID, $leilaoID, $usuarioID) {

        try {
            return $this->lanceDAO->salvarSimples($lanceID, $leilaoID, $usuarioID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function excluir($lanceID) {

        try {
            if(!isset ($lanceID) || $lanceID <= 0)
                throw new Exception("Codigo do Lance Nao Econtrado!!!");

            $this->lanceDAO->excluir($lanceID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function listar($pagina = 0, $leilaoID = -1, $usuarioID = -1, $carregarDependencias = false) {
        try {
            return $this->lanceDAO->listar($pagina, $leilaoID, $usuarioID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function listarPorOrdem($pagina = 0, $tamanho = 0, $ordem = "lanceID", $direcao = "DESC", $carregarDependencias = false) {
        try {
            return $this->lanceDAO->listarPorOrdem($pagina, $tamanho, $ordem, $direcao, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function buscarPorID($lanceID, $carregarDependencias = false) {
        try {
            if(!isset ($lanceID) || $lanceID <= 0)
                throw new Exception("Codigo do Lance Nao Econtrado!!!");
            return $this->lanceDAO->buscarPorID($lanceID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function total($leilaoID = -1, $usuarioID = -1) {
        try {
            return $this->lanceDAO->total($leilaoID, $usuarioID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }
}
?>
